/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.tkgarment.system.dao;

import com.tkgarment.system.domain.TitleName;
import com.tkgarment.system.factory.DAOFactory;
import com.tkgarment.system.inf.IDAO;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *
 * @author zraj
 */
public class TitleDAO extends AbstractDAO implements IDAO<TitleName, Integer> {

    @Override
    public List<TitleName> getAll() throws Exception {
         String sql = "select * from title order by "+ TitleName.field_title_id +" ASC";
         if (this.getCon() == null) {
            this.setCon(DAOFactory.creatConnection());
        }
        List<Map<String, Object>> result = this.getCon().queryList(sql);
        List<TitleName> tn = new ArrayList<>();
        for (Map<String, Object> map : result) {
            TitleName t = new TitleName();
            t.setTitleID(Integer.parseInt(map.get(TitleName.field_title_id).toString()));
            t.setTitleTH(map.get(TitleName.field_title_th).toString());
            t.setTitleEN(map.get(TitleName.field_title_en).toString());
            tn.add(t);
        }
        
        return tn;
    }

    @Override
    public int updateSingle(TitleName t, Integer id) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int deleteSingle(TitleName t) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int insertSingle(TitleName t) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public TitleName getById(Integer id) throws Exception {
        String sql = "select * from title where "+ TitleName.field_title_id +" = ?";
        System.out.println(sql);
         if (this.getCon() == null) {
            this.setCon(DAOFactory.creatConnection());
        }
             Map<String, Object> map = this.getCon().querySingle(sql,id);
      
      
            TitleName t = new TitleName();
            t.setTitleID(Integer.parseInt(map.get(TitleName.field_title_id).toString()));
            t.setTitleTH(map.get(TitleName.field_title_th).toString());
            t.setTitleEN(map.get(TitleName.field_title_en).toString());
          
        
        
        return t;
    }
     
}
